package com.huadi.ssm.controller;

import com.huadi.ssm.po.User;
import com.huadi.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;


    @RequestMapping("/hello")
    public String list(Model model){
        List<User> userList = userService.findAll();
        model.addAttribute("users",userList);
        return "hello";
    }

    @RequestMapping("/adduser")
    public String adduser(Model model){
        User user=new User();
        user.setId(11);
        user.setUsername("1001");
        user.setPassword("1001");
        userService.addUser(user);
        return "redirect:/user/hello";
    }
}
